#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>

const int num = 10;
using namespace std;

void Worker()
{
    // 实现工作函数的具体逻辑
    cout << "Worker process with PID: " << getpid() << endl;
}

int main()
{
    int i = 0;
    for (i = 0; i < num; i++)
    {
        pid_t id = fork();
        if (id < 0)
        {
            cerr << "Fork failed" << endl;
            exit(0);
        }
        if (id == 0)
        {
            Worker();
            exit(0);
        }
        sleep(1);
    }

    // 只有父进程执行到这里
    return 0;
}
